using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Member_Shop_TeamSum : Member, IRequiresSessionState
{
	protected Literal LabProductName;
	protected Label Lbtishi;
	protected Literal TeamName1;
	protected Literal CurrentTeamNum1;
	protected Literal TotalTeamNum1;
	protected Repeater Repeater1;
	protected HtmlTableRow TeamName1Tr;
	protected Literal TeamName2;
	protected Literal CurrentTeamNum2;
	protected Literal TotalTeamNum2;
	protected Repeater Repeater2;
	protected HtmlTableRow TeamName2Tr;
	protected Literal TeamName3;
	protected Literal CurrentTeamNum3;
	protected Literal TotalTeamNum3;
	protected Repeater Repeater3;
	protected HtmlTableRow TeamName3Tr;
	protected Literal TeamName4;
	protected Literal CurrentTeamNum4;
	protected Literal TotalTeamNum4;
	protected Repeater Repeater4;
	protected HtmlTableRow TeamName4Tr;
	protected Literal TeamName5;
	protected Literal CurrentTeamNum5;
	protected Literal TotalTeamNum5;
	protected Repeater Repeater5;
	protected HtmlTableRow TeamName5Tr;
	public int ProductID = 0;
	public int UserID = 0;
	public int OrderFormID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ProductID = Fetch.GetID("ProductID");
		this.OrderFormID = Fetch.GetID("OrderFormID");
		if (this.ProductID <= 0)
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "ProductID"), "");
		}
		this.UserID = base.user.UserID;
		this.ShowTeamBuySum();
		this.ShowCurrentAndTotalNum();
		this.HeadMessage(this.OrderFormID);
	}
	public void ShowTeamBuySum()
	{
		Shop_Product shop_Product = new Shop_Product(this.conn);
		DataTable productByProductID = shop_Product.GetProductByProductID(this.ProductID);
		if (productByProductID.Rows.Count <= 0)
		{
			this.WriteErrMsg("", Language.Get("Common/NotData"), "");
		}
		if (productByProductID.Rows[0]["ProductType"].ToString() != "3")
		{
			this.WriteErrMsg("", Language.Get("Common/NotData"), "");
		}
		int num = (int)productByProductID.Rows[0]["SalerID"];
		this.LabProductName.Text = productByProductID.Rows[0]["ProductName"].ToString();
		string[] array = productByProductID.Rows[0]["TeamName"].ToString().Split(new char[]
		{
			','
		});
		int num2 = Convert.ToInt32(productByProductID.Rows[0]["TeamNum"]);
		Shop_Order shop_Order = new Shop_Order(this.conn);
		DataTable dataTable = new DataTable("Prod");
		DataTable dataTable2 = this.conn.GetDataTable("select * from HLShop_Order where OrderFormID=" + this.OrderFormID);
		int cycle = 0;
		int teameffect = 0;
		if (dataTable2 != null && dataTable2.Rows.Count > 0)
		{
			if (dataTable2.Rows[0]["Cycle"] != DBNull.Value)
			{
				cycle = int.Parse(dataTable2.Rows[0]["Cycle"].ToString());
			}
			if (dataTable2.Rows[0]["Teameffect"] != DBNull.Value)
			{
				teameffect = int.Parse(dataTable2.Rows[0]["Teameffect"].ToString());
			}
		}
		if (num2 >= 1)
		{
			this.TeamName1Tr.Visible = true;
			this.TeamName1.Text = array[0];
			this.Repeater1.DataSource = shop_Order.GetSalerTeamBuyOrderByProductID(this.ProductID, cycle, teameffect, 1);
			this.Repeater1.DataBind();
		}
		if (num2 >= 2)
		{
			this.TeamName2Tr.Visible = true;
			this.TeamName2.Text = array[1];
			this.Repeater2.DataSource = shop_Order.GetSalerTeamBuyOrderByProductID(this.ProductID, cycle, teameffect, 2);
			this.Repeater2.DataBind();
		}
		if (num2 >= 3)
		{
			this.TeamName3Tr.Visible = true;
			this.TeamName3.Text = array[2];
			this.Repeater3.DataSource = shop_Order.GetSalerTeamBuyOrderByProductID(this.ProductID, cycle, teameffect, 3);
			this.Repeater3.DataBind();
		}
		if (num2 >= 4)
		{
			this.TeamName4Tr.Visible = true;
			this.TeamName4.Text = array[3];
			this.Repeater4.DataSource = shop_Order.GetSalerTeamBuyOrderByProductID(this.ProductID, cycle, teameffect, 4);
			this.Repeater4.DataBind();
		}
		if (num2 >= 5)
		{
			this.TeamName5Tr.Visible = true;
			this.TeamName5.Text = array[4];
			this.Repeater5.DataSource = shop_Order.GetSalerTeamBuyOrderByProductID(this.ProductID, cycle, teameffect, 5);
			this.Repeater5.DataBind();
		}
	}
	public string DepositStatus(string ProductID, string TotalPrice, string StrOrderFormID)
	{
		string result = "";
		decimal num = 0m;
		decimal d = 0m;
		int num2 = int.Parse(StrOrderFormID);
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_Product where ProductID=" + int.Parse(ProductID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			num = decimal.Parse(dataTable.Rows[0]["TempSubScriptionRate"].ToString());
		}
		decimal d2 = decimal.Parse(TotalPrice) * num / 100m;
		DataTable dataTable2 = this.conn.GetDataTable("select * from HLShop_Order where OrderFormID=" + num2);
		if (dataTable2 != null && dataTable2.Rows.Count > 0)
		{
			d = decimal.Parse(dataTable2.Rows[0]["MoneyReceipt"].ToString());
		}
		if (num <= 0m)
		{
			result = "免定金";
		}
		else
		{
			if (num > 0m && d < d2)
			{
				result = "未付定金";
			}
			else
			{
				if (num > 0m && d >= d2)
				{
					result = "已付定金";
				}
			}
		}
		return result;
	}
	public string DepositMoney(string ProductID, string TotalPrice)
	{
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_Product where ProductID=" + int.Parse(ProductID));
		string result;
		if (decimal.Parse(dataTable.Rows[0]["TempSubScriptionRate"].ToString()) <= 0m)
		{
			result = "0.00";
		}
		else
		{
			result = Math.Round(decimal.Parse(dataTable.Rows[0]["TempSubScriptionRate"].ToString()) * decimal.Parse(TotalPrice) * decimal.Parse("0.01"), 2).ToString();
		}
		return result;
	}
	protected string GetUserInfo(string feilds, string userid)
	{
		string result;
		if (userid != string.Empty)
		{
			if (Text.IsNumber(userid))
			{
				if (Convert.ToInt32(userid) >= 0)
				{
					object scalar = this.conn.GetScalar(string.Concat(new object[]
					{
						"Select ",
						feilds,
						" From [HL_UserInfo] Where UserID=",
						Convert.ToInt32(userid)
					}), new IDbDataParameter[0]);
					if (scalar != null)
					{
						result = scalar.ToString();
						return result;
					}
					result = string.Empty;
					return result;
				}
			}
		}
		result = string.Empty;
		return result;
	}
	public void ShowCurrentAndTotalNum()
	{
		DataSet dataSet = this.conn.GetDataSet("select * from HLShop_Product where ProductID=" + this.ProductID);
		DataRow dataRow = null;
		if (dataSet != null && dataSet.Tables[0].Rows.Count > 0)
		{
			dataRow = dataSet.Tables[0].Rows[0];
		}
		int num = int.Parse(dataRow["TeamNumber1"].ToString());
		int num2 = int.Parse(dataRow["TeamNumber2"].ToString());
		int num3 = int.Parse(dataRow["TeamNumber3"].ToString());
		int num4 = int.Parse(dataRow["TeamNumber4"].ToString());
		int num5 = int.Parse(dataRow["TeamNumber5"].ToString());
		int num6 = int.Parse(dataRow["TeamNum"].ToString());
		DataSet dataSet2 = this.conn.GetDataSet("select * from HLShop_TeamRecords where ProductID=" + this.ProductID);
		int num7 = 0;
		int num8 = 0;
		int num9 = 0;
		int num10 = 0;
		int num11 = 0;
		if (dataSet2 != null && dataSet2.Tables[0].Rows.Count > 0)
		{
			DataRow dataRow2 = dataSet2.Tables[0].Rows[0];
			num7 = int.Parse(dataRow2["TeamNum1"].ToString());
			num8 = int.Parse(dataRow2["TeamNum2"].ToString());
			num9 = int.Parse(dataRow2["TeamNum3"].ToString());
			num10 = int.Parse(dataRow2["TeamNum4"].ToString());
			num11 = int.Parse(dataRow2["TeamNum5"].ToString());
		}
		switch (num6)
		{
		case 1:
			this.CurrentTeamNum1.Text = num7.ToString();
			this.TotalTeamNum1.Text = num.ToString();
			break;
		case 2:
			this.CurrentTeamNum1.Text = num7.ToString();
			this.TotalTeamNum1.Text = num.ToString();
			this.CurrentTeamNum2.Text = num8.ToString();
			this.TotalTeamNum2.Text = num2.ToString();
			break;
		case 3:
			this.CurrentTeamNum1.Text = num7.ToString();
			this.TotalTeamNum1.Text = num.ToString();
			this.CurrentTeamNum2.Text = num8.ToString();
			this.TotalTeamNum2.Text = num2.ToString();
			this.CurrentTeamNum3.Text = num9.ToString();
			this.TotalTeamNum3.Text = num3.ToString();
			break;
		case 4:
			this.CurrentTeamNum1.Text = num7.ToString();
			this.TotalTeamNum1.Text = num.ToString();
			this.CurrentTeamNum2.Text = num8.ToString();
			this.TotalTeamNum2.Text = num2.ToString();
			this.CurrentTeamNum3.Text = num9.ToString();
			this.TotalTeamNum3.Text = num3.ToString();
			this.CurrentTeamNum4.Text = num10.ToString();
			this.TotalTeamNum4.Text = num4.ToString();
			break;
		case 5:
			this.CurrentTeamNum1.Text = num7.ToString();
			this.TotalTeamNum1.Text = num.ToString();
			this.CurrentTeamNum2.Text = num8.ToString();
			this.TotalTeamNum2.Text = num2.ToString();
			this.CurrentTeamNum3.Text = num9.ToString();
			this.TotalTeamNum3.Text = num3.ToString();
			this.CurrentTeamNum4.Text = num10.ToString();
			this.TotalTeamNum4.Text = num4.ToString();
			this.CurrentTeamNum5.Text = num11.ToString();
			this.TotalTeamNum5.Text = num5.ToString();
			break;
		}
	}
	public void HeadMessage(int OrderFormID)
	{
		string str = "";
		int num = 0;
		decimal d = 0m;
		decimal d2 = 0m;
		decimal d3 = 0m;
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_Product where ProductID=" + this.ProductID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			d3 = decimal.Parse(dataTable.Rows[0]["TempSubScriptionRate"].ToString());
		}
		dataTable.Dispose();
		DataTable dataTable2 = this.conn.GetDataTable("select * from HLShop_Order where OrderFormID=" + OrderFormID);
		if (dataTable2.Rows.Count > 0 && dataTable2 != null)
		{
			int num2 = int.Parse(dataTable2.Rows[0]["Cycle"].ToString());
			if (dataTable2.Rows[0]["Remembereffect"] == null || dataTable2.Rows[0]["Remembereffect"].ToString() == "")
			{
				num = 0;
			}
			else
			{
				num = int.Parse(dataTable2.Rows[0]["Remembereffect"].ToString());
			}
			d = decimal.Parse(dataTable2.Rows[0]["MoneyReceipt"].ToString());
			d2 = d3 * decimal.Parse(dataTable2.Rows[0]["MoneyGoods"].ToString()) / 100m;
			str = dataTable2.Rows[0]["OrderFormNum"].ToString();
		}
		dataTable2.Dispose();
		if (num == 1 && d >= d2)
		{
			this.Lbtishi.Visible = true;
			this.Lbtishi.Text = "温馨提示：该团购虽已达到团购的数量，但还有别的会员还未交定金，所以该定单还未生效，你可以通过以下联系方式通知他们！";
		}
		else
		{
			if (num == 1)
			{
				this.Lbtishi.Visible = true;
				this.Lbtishi.Text = "温馨提示：您还未交定金，请尽快<a href='Shop_BuyOrder.aspx?OrderFormNum=" + str + "'>进入订单</a>进行交款";
			}
		}
	}
}
